import { I18n, TranslateOptions, Scope as I18nScope } from 'i18n-js';
import * as RNLocalize from 'react-native-localize';

// 导入语言文件
import zh from './locales/zh.json';
import en from './locales/en.json';

const i18nInstance = new I18n();
// 加载语言资源
i18nInstance.translations = {
    en,
    zh
};

// 如果找不到翻译，返回原文
i18nInstance.missingBehavior = 'guess';

// 初始化 locale
const fallback = { languageTag: 'en', isRTL: false };
const { languageTag } = RNLocalize.findBestLanguageTag(Object.keys(i18nInstance.translations)) || fallback;
i18nInstance.locale = languageTag;

const switchLanguage = async (lang?: string) => {};

const t = i18nInstance.t.bind(i18nInstance);

export { I18n, switchLanguage, t };
export type { TranslateOptions, I18nScope };
export default i18nInstance;
